<?php
function JudgeNetIp($ip,$mask)
{
	return  long2ip(bindec((decbin(ip2long($ip)) & decbin(ip2long($mask)))));
}

function GetBroadCast($ip, $mask)
{
	$mask_bin = decbin(ip2long($mask));
	$ip_bin = decbin(ip2long($ip));

	print $ip_bin. '\n'. $mask_bin;
	print '\n';
	
	$bin = ( $ip_bin | (~$mask_bin)) ;
	print "\n". $bin;
	$ret = long2ip (bindec($bin));
	return $ret;
}


function GetMaskLen($mask)
{
	$tmp = decbin(ip2long($mask));
	foreach (count_chars($tmp, 1) as $i => $val)
	{
		if ($i == 49 )
			return  $val;
	}
}

include_once "function_log_define.php";
function SysLogString($l, $s)
{
	define_syslog_variables();
	// open syslog, include the process ID and also send
	// the log to standard error, and use a user defined
	// logging mechanism
	openlog("Mini", LOG_PID , LOG_LOCAL0);

    	$access = date("Y/m/d H:i:s");

	switch ($l)
	{
	case 1:
       		syslog(LOG_ALERT,
		"Client=$_SERVER[REMOTE_ADDR];Server=$_SERVER[SERVER_ADDR];Time=\"$access\";Event=\"$s\";");
		break;

	case 2:
       		syslog(LOG_NOTICE,
		"Client=$_SERVER[REMOTE_ADDR];Server=$_SERVER[SERVER_ADDR];Time=\"$access\";Event=\"$s\";");
		break;

	case 3:
       		syslog(LOG_INFO,
		"Client=$_SERVER[REMOTE_ADDR];Server=$_SERVER[SERVER_ADDR];Time=\"$access\";Event=\"$s\";");
		break;

	default:
       		syslog(LOG_INFO,
		"Client=$_SERVER[REMOTE_ADDR];Server=$_SERVER[SERVER_ADDR];Time=\"$access\";Event=\"$s\";");
		break;
	}
	
	closelog();
}

?>

